/*
 * JaCoLiB
 * Copyright (C) 2008 Alessandro Serra
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

package it.gashale.jacolib.rpc;

import it.gashale.jacolib.core.EvalError;
import it.gashale.jacolib.core.JacolibError;
import it.gashale.jacolib.core.ParserError;
import it.gashale.jacolib.core.TargetError;

public abstract class RPCMethodHandler {
	public RPCResponse handles(RPCRequest req) throws JacolibError {
		RPCResponse res=new RPCResponse();
		try {
			res.setResult(safe_handles(req));
		} catch(TargetError e) {
			res.setErr("target", e.getMessage());
		} catch(ParserError e) {
			res.setErr("parser", e.getMessage());
		} catch(EvalError e) {
			res.setErr("eval", e.getMessage());
		}
		return res;
	}
	public Object arg(RPCRequest req, int i) {
		return req.parameters.elementAt(i);
		
	}
	public abstract Object safe_handles(RPCRequest req) throws JacolibError;
}
